<!-- 整个文章列表页面 -->
<!-- 整个文章列表页面 -->
<template>
  <div>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
    <van-cell v-for="item in list" :key="item.aut_id">
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{item.title}}</span>
 <img v-lazy="item.cover.images[0]" alt="" v-if="item.cover.type === 1" class="thumb">
    </div>

<!-- 三张图片 -->
<div class="thumb-box" v-if="item.cover.type > 1">
    <img v-for="(imgsrc, i) in item.cover.images" :key="i" :src="imgsrc" alt="" class="thumb">
          <!-- <img :src="obj.cover.images[0]" alt=""> -->
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <span>{{ item.aut_name }} &nbsp;&nbsp; {{ item.comm_count }}评论 &nbsp;&nbsp; {{ item.pubdate }}</span>
          <!-- 关闭按钮 -->
          <van-icon name="cross" />
        </div>
      </template>
    </van-cell>
    </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { MainlistAPI } from '../../../api/index'
export default {
  data () {
    return {
      list: [],
      refreshing: false,
      loading: false,
      finished: false
    }
  },
  props: ['id'],
  methods: {
    onLoad () {
      this.getlist()
    },
    async getlist () {
      const [, res] = await MainlistAPI({
        channel_id: this.id
      })
      console.log(res.data.data.results)
      this.list = res.data.data.results
      this.refreshing = false
      this.loading = false
      if (res.data.data.results.length === 0) {
        this.finished = true
      } else {
        res.data.data.results.forEach(obj => this.list.push(obj))
      }
    },
    onRefresh () {
      this.list = []
      this.getlist()
    }
  },
  created () {
    this.getlist()
  }
}
</script>

<style scoped lang="less">
.title-box { // 标题样式
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.label-box { // label描述样式
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.thumb {
  // 矩形黄金比例：0.618
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
